<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>优田儿童成长中心</title>
    <link href="/static/assets/fontAwesome/css/fontawesome-all.min.css" rel="stylesheet">
    <link href="/static/assets/css/lib/themify-icons.css" rel="stylesheet">
    <link href="/static/assets/css/lib/mmc-chat.css" rel="stylesheet"/>
    <link href="/static/assets/css/lib/sidebar.css" rel="stylesheet">
    <link href="/static/assets/css/lib/bootstrap.min.css" rel="stylesheet">
    <link href="/static/assets/css/lib/nixon.css" rel="stylesheet">
    <link href="/static/assets/lib/lobipanel/css/lobipanel.min.css" rel="stylesheet">
    <link href="/static/assets/css/style.css" rel="stylesheet">
    <link href="/static/css/datetime.css" rel="stylesheet">
</head>

<body>
<div class="sidebar sidebar-hide-to-small sidebar-shrink sidebar-gestures">
    <div class="nano">
        <div class="nano-content">
            <ul>
                <li>
                    <a href="/home/"><i class="ti-bar-chart"></i> 统计数据</a>
                </li>
                <li class="active">
                    <a href="/teacher/"><i class="ti-user"></i> 教师管理<span
                            class="sidebar-collapse-icon ti-angle-right"></span></a>
                </li>
                <li>
                    <a href="/child/"><i class="ti-user"></i> 幼儿管理</a>
                </li>
                <li>
                    <a href="/posts/"><i class="ti-desktop"></i> 岗位管理</a>
                </li>
            </ul>
        </div>
    </div>
</div>
<div class="header">
    <div class="pull-left">
        <div class="logo">
            <a>
                <img id="logoImg" src="/static/img/yt1.png" data-logo_big="/static/img/yt1.png"
                     data-logo_small="/static/img/yt3.png" alt="Nixon"/>
            </a>
        </div>
        <div class="hamburger sidebar-toggle">
            <span class="ti-menu"></span>
        </div>
    </div>
    <div class="pull-right p-r-15">
        <ul>
            <li class="header-icon dib">
                <img class="avatar-img" src="/static/assets/images/avatar/1.jpg" alt=""/> <span
                    class="user-avatar"><span th:text="${session.username}"></span>&nbsp;&nbsp;&nbsp;<i
                    class="ti-angle-down f-s-10"></i></span>
                <div class="drop-down dropdown-profile">
                    <div class="dropdown-content-body">
                        <ul>
                            <li><a href="/exit/"><i class="ti-power-off"></i> <span>注销</span></a></li>
                        </ul>
                    </div>
                </div>
            </li>
        </ul>
    </div>
</div>
<div class="content-wrap">
    <div class="main">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-8 p-0">
                    <div class="page-header">
                        <div class="page-title">
                            <h1>教师管理</h1>
                        </div>
                    </div>
                </div>
                <div class="col-lg-4 p-0">
                    <div class="page-header">
                        <div class="page-title">
                            <ol class="breadcrumb text-right">
                                <a href="javascript:history.back()" class="btn-link" style="font-size: 16px;" id="back">
                                    <span class="glyphicon glyphicon-triangle-left" aria-hidden="true"></span>返回
                                </a>
                            </ol>
                        </div>
                    </div>
                </div>
            </div>
            <div class="main-content">
                <div class="row">
                    <div class="card alert">
                        <div class="card-header">
                            <h4>添加【<span id="teacher-name">教师姓名</span>】教师工资</h4>
                            <div class="card-header-right-icon">
                            </div>
                        </div>
                        <div class="card-body">
                            <div class="basic-elements">
                                <form id="add-salary-form" method="post">
                                    <input type="hidden" name="tid" id="tid-hidden">
                                    <input type="hidden" name="ttype" id="ttype-hidden">
                                    <div class="row">
                                        <div class="col-lg-6">
                                            <div class="form-group">
                                                <label class="badge badge-dark">工资月份</label>
                                                <input id="datetimepicker" name="month"
                                                       class="form-control input-text datetimepicker-input" type="text"
                                                       placeholder="请选择工资月份" readonly required>
                                            </div>
                                            <h5 class="badge badge-primary">基本工资部分</h5>
                                            <div class="form-group">
                                                <label>底薪</label>
                                                <input class="form-control" type="text" placeholder="请输入教师底薪"
                                                       value="0" name="base_sal" required>
                                            </div>
                                            <div class="form-group">
                                                <label>社保补助</label>
                                                <input class="form-control" type="text" placeholder="请输入社保补助"
                                                       value="0" name="subsidy" required>
                                            </div>
                                            <div class="form-group">
                                                <label>学历补助</label>
                                                <input class="form-control" type="text" placeholder="请输入学历补助"
                                                       value="0" name="edu" required>
                                            </div>
                                            <div class="form-group">
                                                <label>全勤</label>
                                                <input class="form-control" type="text" placeholder="请输入全勤数据"
                                                       value="0" name="full_time" required>
                                            </div>
                                            <div class="form-group">
                                                <label>工龄</label>
                                                <input id="tyear-show" class="form-control" type="text" value="0" readonly>
                                            </div>
                                            <div class="form-group">
                                                <label>话补</label>
                                                <input class="form-control" type="text" placeholder="请输入话补"
                                                       value="0" name="phone" required>
                                            </div>

                                            <h5 class="badge badge-pink">奖金部分</h5>

                                            <div class="form-group">
                                                <label>卫生奖</label>
                                                <input class="form-control" type="text" value="0"
                                                       placeholder="请输入卫生奖" name="health" required>
                                            </div>
                                            <div class="form-group">
                                                <label>安全奖</label>
                                                <input class="form-control" type="text" value="0"
                                                       placeholder="请输入教师安全奖" name="safe" required>
                                            </div>
                                            <div class="form-group">
                                                <label>教育教学</label>
                                                <input class="form-control" type="text" value="0"
                                                       placeholder="请输入教师教育教学" name="class_hour" required>
                                            </div>
                                            <div class="form-group">
                                                <label>家长服务</label>
                                                <input class="form-control" type="text" value="0"
                                                       placeholder="请输入家长服务奖" name="parent" required>
                                            </div>
                                            <h5 class="badge badge-dark">延点班课时费</h5>
                                            <div class="form-group">
                                                <label>课时数</label>
                                                <input class="form-control" type="text" value="0"
                                                       placeholder="请输入课时数" name="num" required>
                                            </div>
                                            <h5 class="badge badge-pink">岗位工资</h5>
                                            <div class="form-group">
                                                <label>选择岗位</label>
                                                <select class="form-control" name="post_sal" id="post-sal-select" required></select>
                                            </div>
                                            <h5 class="badge badge-pink">工龄工资</h5>
                                            <div class="form-group">
                                                <label>工龄工资</label>
                                                <input id="yearsal" class="form-control" type="text" value="0" placeholder="请输入工龄工资" name="year" readonly required>
                                            </div>
                                            <h5 class="badge badge-primary">业绩提成</h5>
                                            <div class="form-group">
                                                <label>业绩奖金</label>
                                                <input class="form-control" type="text" value="0"
                                                       placeholder="请输入实际出勤天数" name="comm" required>
                                            </div>
                                            <div class="form-group">
                                                <input type="submit" class="btn btn-success m-b-10 m-l-5"
                                                       value="确认添加">
                                                <a href="javascript:history.back()"
                                                   class="btn btn-warning m-b-10 m-l-5">返回</a>
                                            </div>
                                        </div>
                                        <div class="col-lg-6">
                                            <div class="form-group">
                                                <img src="/static/img/teacher.png" width="500"/>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            Copyright &copy; 2024
        </div>
    </div>
</div>
<script src="/static/assets/js/lib/jquery.min.js"></script>
<script src="/static/assets/js/lib/jquery.nanoscroller.min.js"></script>
<script src="/static/assets/js/lib/sidebar.js"></script>
<script src="/static/assets/js/lib/bootstrap.min.js"></script>
<script src="/static/assets/js/lib/mmc-common.js"></script>
<script src="/static/assets/js/lib/mmc-chat.js"></script>
<script src="/static/assets/js/lib/chart-js/Chart.bundle.js"></script>
<script src="/static/assets/js/lib/chart-js/chartjs-init.js"></script>
<script src="/static/assets/js/lib/datamap/d3.min.js"></script>
<script src="/static/assets/js/lib/datamap/topojson.js"></script>
<script src="/static/assets/js/lib/datamap/datamaps.world.min.js"></script>
<script src="/static/assets/js/lib/datamap/datamap-init.js"></script>
<script src="/static/assets/lib/lobipanel/js/lobipanel.js"></script>
<script src="/static/assets/js/scripts.js"></script>
<script src="/static/js/H-ui.min.js"></script>
<script>
    $(document).ready(function () {
        const urlParams = new URLSearchParams(window.location.search);
        const tid = urlParams.get("id");
        const ttype = urlParams.get("sid"); 

        $('input[name="tid"]').val(tid);
        $('input[name="ttype"]').val(ttype);

        $.ajax({
            url: '/api/v1/manager/teacher/info/' + tid,
            method: 'GET',
            success: function (res) {
                if (res.code === 200) {
                    const teacher = res.data;
                    $('#teacher-name').text(teacher.tname);

                    const tyear = parseInt(teacher.tyear || 0);
                    $('#tyear-show').val(tyear + ' 个月');

                    let money = Math.floor(tyear / 12) * 100;
                    if (money < 100) {
                        money = 100;
                    }
                    $('#yearsal').val(money);
                } else {
                    alert("教师信息加载失败：" + res.message);
                }
            },
            error: function () {
                alert("请求教师信息失败");
            }
        });

        $.ajax({
            url: '/api/v1/manager/posts/all',
            method: 'GET',
            success: function (res) {
                if (res.code === 200) {
                    const list = res.data;
                    const select = $('#post-sal-select');
                    list.forEach(p => {
                        const option = `<option value="${p.post_sal}">${p.pname}</option>`;
                        select.append(option);
                    });
                } else {
                    alert('岗位信息加载失败：' + res.message);
                }
            },
            error: function () {
                alert('岗位信息请求失败，请稍后再试');
            }
        });

        $('#datetimepicker').datetimepicker({
            language: 'zh-cn',
            format: 'yyyy-mm',
            autoclose: true,
            todayBtn: true,
            todayHighlight: true,
            startView: 'year',
            minView: 'year',
            maxView: 'year'
        });

        $('#add-salary-form').submit(function (e) {
            e.preventDefault();
            const formData = $(this).serialize();
            $.ajax({
                url: '/api/v1/manager/gsal/add',
                method: 'POST',
                data: formData,
                success: function (res) {
                    if (res.code === 200) {
                        alert('添加成功');
                        window.location.href = document.referrer;
                    } else {
                        alert('添加失败: ' + res.message);
                    }
                },
                error: function () {
                    alert('请求失败，请稍后重试');
                }
            });
        });
    });
</script>
<style>
    .copyrights {
        text-indent: -9999px;
        height: 0;
        line-height: 0;
        font-size: 0;
        overflow: hidden;
    }
</style>
<div class="copyrights">
    <h3>&copy; 版权所有 | </h3>
</div>
</body>
</html>